var app = getApp()
var co = require('../../js/common.js')
Page({
    data: {
        isShowInputLabelArr: [false, false, false, false],
        waiter: ''
    },

    onLoad: function (opt) {
        if (!co.isEmpty(opt.waiter)){
            var obj = JSON.parse(opt.waiter);
            this.setData({
                waiter: obj,
                isShowInputLabelArr: [true, true, true, true]
            })
        }
    },
    submitWaiterInfo: function (e) {
        var param = e.detail.value
        if (co.isEmpty(param.sort)) {
            param.sort =0
        }

        param.uid = app.globalData.shopInfo.userid
        var waiter = this.data.waiter
        if (waiter) {
            param.id = waiter.id
            param.sql = 'update'
        } else {
            param.sql = 'insert'
        }
        var that = this
        app.getJsonData('api/admin/waiter_save.php', param, function (res) {
            console.log('waiter_save:res', res)
            that.reportResult(res)
        })
    },

    reportResult: function (res) {
        if (res.code == 0) {
            app.noticeUpdateWaiterList(res.data.waiter)
            wx.navigateBack();
        } else {
            wx.showToast({
                title: res.message,
            })
        }
    },

    showInputLabel: function (e) {
        if (e.detail.value.length > 1) return;
        var index = Number(e.currentTarget.id);
        var isShowArray = this.data.isShowInputLabelArr;
        isShowArray[index] = true;

        this.setData({
            isShowInputLabelArr: isShowArray
        })
    },


    onShareAppMessage: function () {

    }
})